//package org.arl.modem.linktuner;
//
////No idea why i cannot send a message from this class.
//import java.util.Arrays;
//
//import org.arl.modem.FAPIMessage;
//import org.arl.modem.link.Link;
//import org.arl.modem.phy.Physical;
//
//import com.sun.source.tree.SwitchTree;
//
//public class protocol extends linkTuner{
//	
//	
//	//Master sends out a request to the slave to set some scheme params 
//	boolean setSchemeRequest(int recommendedScheme, int Scheme_Params_index, int Scheme_Params_Values_index){
//		FAPIMessage req=createMessage(FAPIMessage.REQUEST,link);
//		req.add("protocol",linkTuner.LINK_TUNER_PROTOCOL_ID);
//	    req.add("destination", Link.BROADCAST_ADDR);
//		byte[] rScheme=new byte[1];
//		rScheme[0]=0x01;     //TYPE_SET_SCHEME_PARAM_M;
//		req.setData(rScheme);
//		FAPIMessage reply=request(req, 2000);
//		log.fine("perf = "+req.getPerformative()+"data[0] = "+req.getData()[0]+"protocol = "+req.getAsInteger("protocol", -1));
//		if(reply != null && reply.getPerformative() == FAPIMessage.AGREE){
//			log.fine("master has sent a request to set parameter "+(Scheme_Params[Scheme_Params_index])+" to "+(Scheme_Params_Values[Scheme_Params_index][Scheme_Params_Values_index])+" for scheme "+(byte)recommendedScheme);
//			return true;
//		}
//		else {
//			log.warning("not successful in sending out set scheme parameter request");
//			diagnose(reply);
//			return false;
//		}
//	}
//	
//	void setSchemeParam(FAPIMessage msg, int value){
//		log.fine("inside the setSchemeParam(FAPIMessage msg) method");
//		FAPIMessage req=createMessage(FAPIMessage.REQUEST, phy, Physical.PARAM_SET);
//		req.setContent(PARAM_SET);
//		req.add("family", msg.getData()[1]);
//		req.add("parameter", Scheme_Params[msg.getData()[2]]);
//		req.add("value",Scheme_Params_Values[msg.getData()[2]][msg.getData()[3]]);
//		FAPIMessage reply=request(req, 2000);
//		log.fine("just asked the phy layer to set params");
//		if (reply == null || reply.getPerformative() != FAPIMessage.INFORM){
//	    	log.warning("----seem unable to set phy params :(");
//	    	diagnose(reply);
//	    }
//		else{
//	    	log.fine(" currently, parameter " + reply.getAsInteger("parameter") + " has value= " + reply.getAsInteger("value") + " for scheme " + reply.getAsInteger("family"));
//	    	if(value==1){
//	    		sendSchemeParamAck(msg); //send back an ack iff value==1
//	    	}
//		}
//	}
//	
//	private void sendSchemeParamAck(FAPIMessage msg){
//		log.fine("inside the setSchemeParamAck method");
//		FAPIMessage req=createMessage(FAPIMessage.REQUEST,link);
//		req.add("protocol",LINK_TUNER_PROTOCOL_ID);
//		byte[] rScheme=msg.getData();
//		rScheme[0]=(byte)TYPE_SEND_SCHEME_PARAM_ACK_S;
//		req.setData(rScheme);
//		FAPIMessage reply=request(req, 2000);
//		if(reply != null && reply.getPerformative() == FAPIMessage.AGREE){
//			log.fine("slave has sent an ack back to the master");
//		}
//		else {
//			log.warning("slave is not successful in sending out set scheme parameter ack");
//			diagnose(reply);
//		}
//	}
//	
//	void processSendSchemeParamAck(FAPIMessage msg){
//		int[] schemeParamAck={(int)msg.getData()[1], (int)msg.getData()[2], (int)msg.getData()[3]};
//		if(Arrays.equals(currentSetSchemeParam, schemeParamAck)){
//			log.fine("received ack corresponding to current set scheme param request");
//			setSchemeParam(msg, 0);
//		}
//		else{
//			log.fine("recieved ack does not match current set scheme param request" +schemeParamAck[0]+" , "+schemeParamAck[1]+" , "+schemeParamAck[2]);
//		}
//	}
//	
//	void diagnose(FAPIMessage reply){
//		if(reply==null){
//			log.fine("reply=null");
//		}
//		else{
//			switch (reply.getPerformative()){
//				case FAPIMessage.FAILURE:
//					log.fine("perf=failiure");
//					break;
//				case FAPIMessage.REFUSE:
//					log.fine("perf=refuse");
//					break;
//				case FAPIMessage.DISCONFIRM:
//					log.fine("perf=disconfirm");
//					break;
//				case FAPIMessage.NOT_UNDERSTOOD:
//					log.fine("perf=not-understood");
//				default:
//					log.fine("Perf is NOT failiure/refuse/disconfirm/not_understood...");
//					break;
//			}
//		}
//		log.fine("exiting diagnose");
//	}
//	
//}
